{include file="header.html"}
<script type="text/javascript" src="templates/js/jquery.colorbox.js" charset="utf-8"></script>
<link href="templates/style/colorbox.css" rel="stylesheet" type="text/css" />
<script src="templates/jsnew/MediaStreamRecorder.js"> </script>
<script type="text/javascript">
$(function(){
	$('#less_form').validate({
		errorPlacement: function(error, element){
		},
		success       : function(element){
			$(element).next('.noerror').show();
			$(element).remove();
		},
		rules : {
			g_owner : {
				required : true
			},
			g_owner_tel :{
				required : true
			},
			g_loading_place :{
				required : true
			},
			g_loading_date :{
				required : true
			},
			g_unloading_place :{
				required : true
			},
			g_unloading_date :{
				required : true
			},
			g_consignee :{
				required : true
			},
			g_consignee_tel :{
				required : true
			},
			g_consignor :{
				required : true
			},
			g_consignor_tel :{
				required : true
			}
		},
		messages : {
			g_owner : {
				required : '货主必填'
			},
			g_owner_tel : {
				required : '货主电话必填'
			},
			g_loading_place : {
				required : '装货地必填'
			},
			g_loading_date : {
				required : '装货时间必填'
			},
			g_unloading_place : {
				required : '卸货地必填'
			},
			g_unloading_date : {
				required : '卸货时间必填'
			},
			g_consignee : {
				required : '收货人必填'
			},
			g_consignee_tel : {
				required : '收货人电话必填'
			},
			g_consignor : {
				required : '发货人必填'
			},
			g_consignor_tel : {
				required : '发货人电话必填'
			}
		}
	});
    $('#g_tgdate').datetimepicker({changeMonth: true,changeYear: true});
	$('#g_rdate').datetimepicker({changeMonth: true,changeYear: true});
	$('#g_loading_date').datetimepicker({changeMonth: true,changeYear: true});
	$('#g_unloading_date').datetimepicker({changeMonth: true,changeYear: true});
    i=1000;
    $("#add").click(function(){
		var t=$("#templetesub").html();
		t=t.replace(/{line}/g,i);
    	$("#addtr").append(t);
    	i+=1;
    });
	$("[id^='subdel_']").live('click',function(){
		var i=$(this).attr("item");
		var t=$(this);
		if(confirm("是否要删除此行?")){
			if(i>0){
				$.ajax({
					type: "post",
					url: "index.php?app=goodsless&act=delsub",
					data: {id:i},
					dataType: "json",
					success: function(data){
						if(data.done){
							t.parent().parent().remove();
						}else{
							alert(data.msg);
						}
					}
				});
			}else{
				$(this).parent().parent().remove();
			}
		}
	});
    $("#sub").click(function(){
		$("input[id^='gs_name_']").each(function(){
			var gs_name = $(this).val();
			var item = $(this).attr("item");
			if(item=="{line}"){
				bug = true;
			}else{
				if(gs_name==''){
					$(this).addClass("error");
					bug = false;
				}
			}
		});
		$("input[id^='gs_piece_']").each(function(){
			var gs_piece = $(this).val();
			var item = $(this).attr("item");
			if(item=="{line}"){
				bug = true;
			}else{
				if(gs_piece==''){
					$(this).addClass("error");
					bug = false;
				}
			}
		});
		$("input[id^='gs_weight_']").each(function(){
			var gs_weight = $(this).val();
			var item = $(this).attr("item");
			if(item=="{line}"){
				bug = true;
			}else{
				if(gs_weight==''){
					$(this).addClass("error");
					bug = false;
				}
			}
		});
		$("input[id^='gs_size_']").each(function(){
			var gs_size = $(this).val();
			var item = $(this).attr("item");
			if(item=="{line}"){
				bug = true;
			}else{
				if(gs_size==''){
					$(this).addClass("error");
					bug = false;
				}
			}
		});
		if( bug == true){
			$("#less_form").submit();
		}
		$("input[id^='gs_name_']").focus(function(){
			$(this).removeClass("error");

		})
		$("input[id^='gs_piece_']").focus(function(){
			$(this).removeClass("error");

		})
		$("input[id^='gs_weight_']").focus(function(){
			$(this).removeClass("error");

		})
		$("input[id^='gs_size_']").focus(function(){
			$(this).removeClass("error");

		})
	});

    $("#himg").live('click',function(){
		var id=$(this).attr("item");
		$w=$(window).width();
      	$h=$(window).height();
      	$w=$w*0.7;
      	$("#hzframe").attr("src","index.php?app=datarefer&act=choosehz");
		$("#hzframe").width($w);
      		$.colorbox({
          	width : $w+20,
          	height : "650px",
          	inline : true,
          	href : "#hzlist"
      	});
	});
    /*拆分货物弹出层*/
    $("#split").click(function(){
        $w=$(window).width();
        $h=$(window).height();
        $w=$w*0.7;
        $("#tagframe").attr("src","index.php?app=goodsless&act=chooseless&gtid="+$(this).attr("item"));
        $("#tagframe").width($w);
        $.colorbox({
            width : $w+20,
            height : "650px",
            inline : true,
            href : "#taglist"
        });
    });
    $("#remove").click(function(){
        if(confirm('确定取消提交货物？')){
            var gtid = $(this).attr("item");
            $.ajax({
                type:"post",
                url:'index.php?app=goodstrunk&act=remove',
                data: {gtid:gtid},
                dataType: "json",
                success:function(data){
					if(data.done){
						window.location.href="index.php?app=goodstrunk&act=edit&id="+gtid;
					}else{
						alert(data.msg);
					}
                }
            });
        }
    })
});
var mainid=0;
var mapsender=null;
var newmapid;
//地图选择
function mapselect(mapid,id,sender){
	newmapid=mapid;
	mainid=id;
	mapsender=sender;
	$w=$(window).width();
	$h=$(window).height();
	$w=$w*0.7;
	$("#mapframe").attr("src","index.php?app=datarefer&act=mapselect&lng="+parseFloat($("[id='lng_"+mainid+"']").val())+"&lat="+parseFloat($("[id='lat_"+mainid+"']").val())+"&ret=window.parent.mapresult&address="+$(mapid).val());
	$("#mapframe").width($w);
	$.colorbox({
		width : $w+20,
		height : "650px",
		inline : true,
		href : "#maplist"
	});
}

function cargotimeimg (type,number,id){
	if(type==1){
		if(number==1){
			$('#g_loading_date'+id).focus();
		}else if(number==2){
			$('#g_unloading_date'+id).focus();
		}else if (number==3){
			$('#g_tgdate'+id).focus();
		}else if(number==4){
			$('#g_rdate'+id).focus();
		}
	}else if(type==3){
		$('#h_required_service_date_'+id).focus();
	}
}



function mapresult(lng,lat,addr){
	$('mapframe').colorbox.close();
	$("[id='lat_"+mainid+"']").val(lat);
	$("[id='lng_"+mainid+"']").val(lng);
	if(mapsender!=null){
		$(mapsender).html()
	}
	
	   if(newmapid=="#g_loading_place"){
			$("#g_loading_place").val(addr);
		}
	   if(newmapid=="#g_unloading_place"){
			$("#g_unloading_place").val(addr);
		}
	  
	
	
	if(lat>0&&lng>0){
		$("#mapimg_"+mainid).attr("src","templates/images/newadmin/map1.png");
	}

}
//货主新弹框
function changehz(id,name,hzid,linkman,linktel){
	$('hzframe').colorbox.close();
	$("#g_ownertid").val(id);
	$("#g_owner").val(name);
	$("#g_owner_tel").val(linktel);
}
function delete_order(order_id){  
	


		
		if(confirm('确定删除整行？')){
			

	        $.ajax({
	            type:"get",
	            url:'index.php?app=goodstrunk&act=del&id='+order_id,
	            		
	            success:function(msg){
	             
	                $("#tr_"+order_id).remove();
	            }
	        });
		}
 };
</script>
<div id="rightTop">
	<p class="info_menu">
		<a href="javascript:void(0);" class="index">控制台</a>&nbsp;>&nbsp;<a href="javascript:void(0);">零担货单</a>&nbsp;>&nbsp;<span>货单编号  {$auth.g_code}</span>
	</p>
	<ul class="subnav">
		<li><a class="btn1" href="index.php?app=goodsless">{$lang.manage}</a>
		</li>
		<!-- {if $auth.g_tid}} -->
		<li>
			<a class="btn1" href="index.php?app=goodsless&amp;act=add">{$lang.add}</a>
		</li>
		<li>
			<span>编辑</span></li>
		<!-- {else} -->
		<li>
			<span>新建</span>
		</li><!-- {/if} -->
	</ul>
</div>
<table id="templetesub" style="display: none">
	<tr>
		<th  class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>品名: </th>
		<td >
			<input type="text" placeholder="品名必填" name="normal[{line}][gs_name]" id="gs_name_{line}" item="{line}" class="infoTableInput" value="">
			<input type="hidden" name="normal[{line}][gs_tid]" value="" >
		</td>

		<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>件数:  </th>
		<td >
			<input type="text" placeholder="件数必填" name="normal[{line}][gs_piece]" id="gs_piece_{line}"  item="{line}" class="infoTableInput" value="">
		</td>

		<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>重量/吨:  </th>
		<td >
			<input type="text" placeholder="重量必填" name="normal[{line}][gs_weight]" id="gs_weight_{line}" item="{line}" class="infoTableInput" value="">
		</td>

		<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>尺码/立方米:  </th>
		<td ><input type="text" placeholder="尺码必填" name="normal[{line}][gs_size]" id="gs_size_{line}" item="{line}" class="infoTableInput" value="">
		</td>
		<th class="paddingT15"></th>
		<td style="white-space: nowrap;">
			<a id="subdel_{line}" item=""  href="javasciprt:;">删除</a>
		</td>
	</tr>
</table>
<div class="info">
	<div class="infoTable" style="padding-left: 10px;padding-top: 20px">
		<!--拆分货物-->
		{if $auth.g_tid && !empty($goodssub)}
			<input class="formbtn" type="button" id="split" item = "{$auth.g_tid}" value="提交货物">
		{/if}
		<!--取消拆分货物-->
		<!--{if $remove}
			<input class="formbtn" type="button" id="remove" item = "{$auth.g_tid}" value="取消提交货物">
		{/if}-->
	</div>
	<form method="post" enctype="multipart/form-data" id="less_form">
		<div class="jui-cut-label fn-mt25">
			<div class="jui-message-bar">基本信息</div>
		</div>
		<input type="hidden" name="wm_code" value="{$auth.wm_code}" class="mls_names">
		<table class="infoTable">
			<tr>
				<th>单号:</th>
				<td style="text-align: left;">
					{$auth.g_code}
					<input 	class='infoTableInput' id="g_code" type='hidden' name='g_code' value='{$auth.g_code}' />
				</td>
				<th class="paddingT15">类型:</th>
				<td style="text-align: left;">
					<input class='infoTableInput' id="g_type" type='hidden' name='g_type' value='' />
					<span id="g_type2">{$auth.g_type|default:零担}</span>
				</td>
				<th class="paddingT15">下单时间:</th>
				<td style="text-align: left;">
					{$auth.g_opdate|date:Y-m-d H:i:s}
				</td>
				<th class="paddingT15">下单人:</th>
				<td style="text-align: left;">
					{$auth.user_name}
				</td>
				<th></th>
				<td></td>
			</tr>
		</table>
		<HR style="FILTER: alpha(opacity = 100, finishopacity = 0, style = 1)" size="1" width="83%" color="#ccc">
		<table class="infoTable">
			<tr>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>货主:</th>
			
				
				
					
				<td style="width: 200px;">
				<input type="hidden" value="{$auth.g_ownertid}" name="g_ownertid" id="g_ownertid_{$s.g_tid}">
				<input type="text"  placeholder="货主必填" value="{$auth.g_owner}" 
				item="{$s.g_tid}" name="g_owner" id="g_owner" 
				class="infoTableInput"
				urldata="index.php?app=datarefer&act=gethz" urlval="index.php?app=datarefer&act=gethzinfo"
				>
					<a href="javascript:void(0);" class="right_a" item="{$s.g_tid}" id="himg"><img src="templates/images/newadmin/serch.png" alt=""></a>
				
				<script>
				refer("g_owner","g_ownertid_{$s.g_tid}");
				</script>
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>货主电话:</th>
				<td class="paddingT15 wordSpacing5" >
					<input class="infoTableInput" id="g_owner_tel" placeholder="必填" type="text" name="g_owner_tel" value="{$auth.g_owner_tel}" />
				</td>
				<th class="paddingT15">货物类型:</th>
				<td class="paddingT15 wordSpacing5" >
					<select class="querySelect" name="g_gtype">{html_options options=$goodstype selected=$auth.g_gtype}</select>
				</td>
			</tr>
			<tr>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>发货人:</th>
				<td class="paddingT15 wordSpacing5" >
					<input type="text" name="g_consignor" value="{$auth.g_consignor}" class="infoTableInput" id="g_consignor">
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>发货人电话:</th>
				<td class="paddingT15 wordSpacing5" >
					<input type="text" name="g_consignor_tel" value="{$auth.g_consignor_tel}" class="infoTableInput" id="g_consignor_tel">
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>装货地:</th>
				<td class="paddingT15 wordSpacing5">
					<input type="hidden" value="{$auth.g_loading_lng}" name="g_loading_lng" id="lng_loading"><!--经度-->
					<input type="hidden" value="{$auth.g_loading_lat}" name="g_loading_lat" id="lat_loading">
					<input type="text" placeholder="装货地必填" value="{$auth.g_loading_place}" name="g_loading_place" id="g_loading_place" class="infoTableInput" urldata="index.php?app=datarefer&act=getaddr" urlval="index.php?app=datarefer&act=getaddrinfo">
					<a href="javascript:void(0);" onclick="mapselect('#g_loading_place','loading',this)" class="right_a">
						{if $auth.g_loading_lat>0&&$auth.g_loading_lng>0}
						<img src="templates/images/newadmin/map1.png" alt="" id="mapimg_loading">
						{else}
						<img src="templates/images/newadmin/map.png" alt="" id="mapimg_loading">{/if}
					</a>
					<script>
						addrrefer("g_loading_place","lng_loading","lat_loading","mapimg_loading");
					</script>
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>装货时间:</th>
				<td class="paddingT15 wordSpacing5" >
					<input placeholder="装货时间必填"  class="infoTableInput" type="text" name="g_loading_date" id="g_loading_date" value="{if $auth.g_loading_date}{$auth.g_loading_date|date:Y-m-d H:i}{else}{/if}" />
					<a href="javascript:void(0);" onclick="cargotimeimg('1','1','');" class="right_a"><img src="templates/images/newadmin/rili.png" alt=""></a>
				</td>
			</tr>
			<tr>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>收货人:</th>
				<td class="paddingT15 wordSpacing5" >
					<input type="text" name="g_consignee" value="{$auth.g_consignee}" class="infoTableInput" id="g_consignee">
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>收货人电话:</th>
				<td class="paddingT15 wordSpacing5" >
					<input type="text" name="g_consignee_tel" value="{$auth.g_consignee_tel}" class="infoTableInput" id="g_consignee_tel">
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>卸货地:</th>
				<td class="paddingT15 wordSpacing5">
					<input type="hidden" value="{$auth.g_unloading_lng}" name="g_unloading_lng" id="lng_unloading"><!--经度-->
					<input type="hidden" value="{$auth.g_unloading_lat}" name="g_unloading_lat" id="lat_unloading">
					<input type="text" placeholder="卸货地必填" value="{$auth.g_unloading_place}" name="g_unloading_place" id="g_unloading_place" class="infoTableInput" urldata="index.php?app=datarefer&act=getaddr" urlval="index.php?app=datarefer&act=getaddrinfo">
					<a href="javascript:void(0);" onclick="mapselect('#g_unloading_place','unloading',this);" class="right_a">
						{if $auth.g_unloading_lat>0&&$auth.g_unloading_lng>0}
						<img src="templates/images/newadmin/map1.png" alt="" id="mapimg_unloading">
						{else}
						<img src="templates/images/newadmin/map.png" alt="" id="mapimg_unloading">{/if}
					</a>
					<script>
						addrrefer("g_unloading_place","lng_unloading","lat_unloading","mapimg_unloading");
					</script>
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>卸货时间:</th>
				<td class="paddingT15 wordSpacing5" >
					<input placeholder="卸货时间必填"  class="infoTableInput" type="text" name="g_unloading_date" id="g_unloading_date" value="{if $auth.g_unloading_date}{$auth.g_unloading_date|date:Y-m-d H:i}{else}{/if}" />
					<a href="javascript:void(0);" onclick="cargotimeimg('1','2','');" class="right_a"><img src="templates/images/newadmin/rili.png" alt=""></a>
				</td>
			</tr>
			<tr>
				<th class="paddingT15">备注:</th>
				<td class="paddingT15 wordSpacing5" colspan="5"><textarea
						name="g_note" id="g_note" rows="3" style="width: 100%">{$auth.g_note}</textarea>
					<label></label>
				</td>
			</tr>
		</table>
		<!-- {if $auth.g_tid}} -->
		<div class="jui-cut-label fn-mt25">
			<div class="jui-message-bar">货物信息
				{if $isbool==1}
					<input style="float:right;" class="formbtn" type="button" id="add" value="添加">
				{/if}
			</div>
		</div>
		<input type="hidden" name="gs_gtid" value="{$auth.g_tid}" >
		<table class="infoTable"  id="addtr">
			{foreach from=$goodssub item=b}
			<tr>
				<th  class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>品名:	</th>
				<td >
					<input type="text" placeholder="品名必填" name="normal[{$b.gs_tid}][gs_name]" id="gs_name_{$b.gs_tid}" item="{$b.gs_tid}" class="infoTableInput" value="{$b.gs_name}">
					<input type="hidden" name="normal[{$b.gs_tid}][gs_tid]" value="{$b.gs_tid}" >
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>件数:  </th>
				<td >
					<input type="text" placeholder="件数必填" name="normal[{$b.gs_tid}][gs_piece]" id="gs_piece_{$b.gs_tid}" item="{$b.gs_tid}" class="infoTableInput" value="{$b.gs_piece}">
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>重量/吨:  </th>
				<td >
					<input type="text" placeholder="重量必填" name="normal[{$b.gs_tid}][gs_weight]" id="gs_weight_{$b.gs_tid}" item="{$b.gs_tid}" class="infoTableInput" value="{$b.gs_weight}">
				</td>
				<th class="paddingT15"><b style="color: #ff0000">*&nbsp;</b>尺码/立方米:  </th>
				<td >
					<input type="text" placeholder="尺码必填" name="normal[{$b.gs_tid}][gs_size]" id="gs_size_{$b.gs_tid}" item="{$b.gs_tid}" class="infoTableInput" value="{$b.gs_size}">
				</td>
				<th class="paddingT15"></th>
				<td style="white-space: nowrap;">
					{if $isbool==1}
					<a id="subdel_{$b.gs_tid}" item="{$b.gs_tid}"  href="javasciprt:;">删除</a>
					{/if}
				</td>
			</tr>
			{/foreach}
		</table>
		<!-- {/if} -->
		<table class="infoTable">
			<tr>
				<th></th>
				<td class="ptb20" style="text-align: left;">
					{if $isbool==1}
					<input class="formbtn" type="button" id="sub" name="Submit" value="{$lang.submit}" />
					{/if}
				</td>
			</tr>
		</table>
	</form>
</div>
<!--拆单弹出层-->
<div style="display: none"  >
    <div id="taglist">
        <iframe id="tagframe" src="index.php?app=goodsless&act=chooseless" width="" height="600px" frameborder="0" scrolling="no"></iframe>
    </div>
</div>
<!--货主弹出层-->
<div style="display: none"  >
	<div id="hzlist">
		<iframe id="hzframe" width="" height="600px" frameborder="0" scrolling="no"></iframe>
	</div>
</div>
<!--地图弹出层-->
<div style="display: none"  >
	<div id="maplist">
		<iframe id="mapframe" width="" height="600px" frameborder="0" scrolling="no"></iframe>
	</div>
</div>

{include file="footer.html"}
